package com.ruoyi.project.system.modularshow.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.modularshow.domain.ModularShow;
import com.ruoyi.project.system.modularshow.service.IModularShowService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 模块展示Controller
 *
 * @author LCL
 * @date 2021-12-08
 */
@Controller
@RequestMapping("/system/modularshow")
public class ModularShowController extends BaseController
{
    private String prefix = "system/modularshow";

    @Autowired
    private IModularShowService modularShowService;

    @RequiresPermissions("system:modularshow:view")
    @GetMapping()
    public String modularshow()
    {
        return prefix + "/modularshow";
    }

    /**
     * 查询模块展示列表
     */
    @RequiresPermissions("system:modularshow:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ModularShow modularShow)
    {
        startPage();
        List<ModularShow> list = modularShowService.selectModularShowList(modularShow);
        return getDataTable(list);
    }

    /**
     * 导出模块展示列表
     */
    @RequiresPermissions("system:modularshow:export")
    @Log(title = "模块展示", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ModularShow modularShow)
    {
        List<ModularShow> list = modularShowService.selectModularShowList(modularShow);
        ExcelUtil<ModularShow> util = new ExcelUtil<ModularShow>(ModularShow.class);
        return util.exportExcel(list, "modularshow");
    }

    /**
     * 新增模块展示
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存模块展示
     */
    @RequiresPermissions("system:modularshow:add")
    @Log(title = "模块展示", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ModularShow modularShow)
    {
        return toAjax(modularShowService.insertModularShow(modularShow));
    }

    /**
     * 修改模块展示
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        ModularShow modularShow = modularShowService.selectModularShowById(id);
        mmap.put("modularShow", modularShow);
        return prefix + "/edit";
    }

    /**
     * 修改保存模块展示
     */
    @RequiresPermissions("system:modularshow:edit")
    @Log(title = "模块展示", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ModularShow modularShow)
    {
        return toAjax(modularShowService.updateModularShow(modularShow));
    }

    /**
     * 删除模块展示
     */
    @RequiresPermissions("system:modularshow:remove")
    @Log(title = "模块展示", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(modularShowService.deleteModularShowByIds(ids));
    }
}
